//
// Created by RandBII on 2020/12/24.
//

#ifndef FFMPEGFORANDROID_FFMPEGMEDIAPLAYER_H
#define FFMPEGFORANDROID_FFMPEGMEDIAPLAYER_H

#include "decoder/video/VideoDecoder.h"
#include "decoder/audio/AudioDecoder.h"
#include <jni.h>
#include "render/audio/AudioRender.h"
#include "OpenSLRender.h"
#define JAVA_PLAYER_EVENT_CALLBACK_API_NAME "playerEventCallback"

#define MEDIA_PARAM_VIDEO_WIDTH 0X0001
#define MEDIA_PARAM_VIDEO_HEIGHT 0X0002
#define MEDIA_PARAM_VIDEO_DURATION 0X0003


/**
 * ffmpeg 本地播放器
 */
class FFmpegMediaPlayer {

public:
    FFmpegMediaPlayer() = default;

    ~FFmpegMediaPlayer() = default;

    void Init(JNIEnv *env, jobject obj, char *url, int renderType, jobject surface);

    void UnInit();

    void Play();

    void Pause();

    void Stop();

    void SeekToPosition(float position);

    long GetMediaParams(int paramType);

private:

    JNIEnv *GetJNIEnv(bool *isAttached);

    jobject GetJavaObject();

    JavaVM *GetJavaVM();

    static void PostMessage(void *context, int msgType, float msgCode);

    JavaVM *mJavaVM = nullptr;
    jobject mJavaObj = nullptr;

    VideoDecoder *videoDecoder = nullptr;
    AudioDecoder *audioDecoder = nullptr;
    VideoRender *videoRender = nullptr;
    AudioRender *audioRender = nullptr;

};

#endif //FFMPEGFORANDROID_FFMPEGMEDIAPLAYER_H
